package com.marisfrolg.comps;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;

/**
 * @BelongsProject: oauth-demos
 * @BelongsPackage: com.marisfrolg.comps
 * @Author: 毕苗苗
 * @CreateTime: 2023-01-05  15:35
 * @Description: TODO
 * @Version: 1.0
 */
@Component
public class Scan2AuthManager implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        String[] beanNamesForAnnotation = applicationContext.getBeanNamesForAnnotation(RestController.class);
        if(beanNamesForAnnotation.length>0)
        {
            for (String s : beanNamesForAnnotation) {
                Object bean = applicationContext.getBean(s);
                Class<?> clazz=bean.getClass();
                RestController demo=clazz.getAnnotation(RestController.class);
                if(demo!=null) {
                    Method[] methods=clazz.getDeclaredMethods();
                    for(Method method:methods){
                        GetMapping demoMethod=method.getAnnotation(GetMapping.class);
                        System.out.println(demoMethod);
                    }

                }
            }
        }

    }
}